package com.heima.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmUserDTO;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
@Api(value ="自媒体用户controller")
public class WmController {
    @Autowired
    private WmService wmService;
    @GetMapping("/api/v1/user/findByName/{name}")
    public ResponseResult<WmUser> findByName(@PathVariable("name") String name){
        WmUser wmUser = wmService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
        return ResponseResult.okResult(wmUser);
    }
    @PostMapping("/api/v1/user/save")
    public ResponseResult<WmUser>   save(@RequestBody WmUser wmUser){
        wmService.save(wmUser);

        return ResponseResult.okResult(wmUser);
    }
    @PostMapping("/login/in")
    @ApiOperation("自媒体登录方法")
    public ResponseResult login(@RequestBody WmUserDTO wmUserDTO)
    {
        return wmService.login(wmUserDTO);
    }
}
